<?php

use yii\db\Migration;

/**
 * Handles the creation of table `job`.
 */
class m190118_063840_create_job_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('job', [
            'id' => $this->primaryKey(),
            'uid'=>$this->integer()->notNull()->comment("发布者"),
            //区别兼职还是任务
            'type'=>$this->tinyInteger()->notNull()->comment("类型"),
            //根据不同类型有不同意义
            'status'=>$this->tinyInteger()->defaultValue(0)->comment("状态"),
            //10：不屏蔽 other:屏蔽
            'forbidden'=>$this->tinyInteger()->defaultValue(10)->comment("是否屏蔽"),
            'pay_needed'=>$this->tinyInteger()->comment("需要支付"),
            'title'=>$this->string()->comment("招聘名称"),
            'created_at'=>$this->integer()->comment("创建时间"),
            'updated_at'=>$this->integer()->comment("最后更新时间"),
            'content'=>$this->text()->comment("兼职详情"),
            'contact_name'=>$this->string()->comment("联系人姓名"),
            'contact_phone'=>$this->string()->comment("联系人电话"),

        ]);
        $this->createTable('job_info',[
            'id'=>$this->primaryKey(),
            'jid'=>$this->integer()->notNull()->comment("工作id"),
            'job_type'=>$this->integer()->comment("兼职类型(fk)"),
            'mission_type'=>$this->integer()->comment("任务类型(fk)"),
            'img'=>$this->integer()->comment("图片"),
            'color'=>$this->string()->notNull()->defaultValue("#000")->comment("文字颜色"),
            'latitude'=>$this->string()->comment("纬度"),
            'longitude'=>$this->string()->comment("经度"),
            'province_code'=>$this->string()->comment("省行政区划"),
            'city_code'=>$this->string()->comment("市行政区划"),
            'district_code'=>$this->string()->comment("区/县行政区划"),
            'ad_code'=>$this->string()->comment("行政区划码"),
            'ad_type'=>$this->string()->comment("行政区级别"),
            'gender_needed'=>$this->tinyInteger()->defaultValue(0)->comment("性别要求"),
            'age_needed'=>$this->tinyInteger()->defaultValue(0)->comment("年龄要求"),
            'sign_start'=>$this->integer()->comment("报名开始时间"),
            'sign_end'=>$this->integer()->comment("报名结束时间"),
            'work_start'=>$this->time()->comment("上班时间"),
            'work_end'=>$this->time()->comment("下班时间"),
            'salary'=>$this->integer()->comment("工资"),
            'salary_type'=>$this->tinyInteger()->notNull()->defaultValue(0)->comment("工资类型"),
            'pay_typed'=>$this->tinyInteger()->comment("结算方式"),
        ]);
        $this->addForeignKey('fk_jon_user_uid','job','uid','user','id','NO ACTION');
        $this->addForeignKey('fk_jon_jid','job_info','jid','job','id','CASCADE');
        $this->addForeignKey('fk_joninfo_image_img','job_info','img','image','id','NO ACTION');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('job_info');
        $this->dropTable('job');
    }
}
